import java.util.*;
public class Solution1 {
    public void merge(int A[], int m, int B[], int n) {
        int[] ret = new int[m + n];
        int i = 0;
        int j = 0;
        int len = 0;
        while(i < m && j < n){
            if(A[i] < B[j]){
                ret[len] = A[i];
                i++;
            }else{
                ret[len] = B[j];
                j++;
            }
            len++;
        }
        if(i == m){
            while(j < n){
                ret[len] = B[j];
                j++;
                len++;
            }
        } else if (j == n) {
            while(i < m){
                ret[len] = A[i];
                i++;
                len++;
            }
        }
        for (int k = 0; k < m + n; k++) {
            A[k] = ret[k];
        }
    }

    public static void main(String[] args) {
        int[] A = new int[]{1,2,3,0,0,0};
        int[] B = new int[]{4,5,6};
        new Solution1().merge(A,3,B,3);
        System.out.println(Arrays.toString(A));
    }
}